package be.redo.model.entities;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Email;

/**
 * @author Frank
 * 
 */
@Entity
@NamedQueries({
		@NamedQuery(name = "findAantalCustomers", query = "select count(c) from Customer c"),
		@NamedQuery(name = "findAllCustoms", query = "select c from Customer c order by c.email"),
		@NamedQuery(name = "findCustomersByEmailLike", query = "select c from Customer c where c.email like( :email )") })
public class Customer implements Serializable {

	/**
	 * Generated serialVersionUID.
	 */
	private static final long serialVersionUID = -1548968759565762185L;

	/**
	 * Email address used for logging on.
	 */
	@NotNull
	@Email
	private String email;

	/**
	 * password used for logging on.
	 */
	@NotNull
	@Size(min = 32, max = 255)
	private String password;

	// /**
	// * Set of vacations booked a this customer.
	// */
	// @OneToMany(cascade = CascadeType.ALL, mappedBy = "customer")
	// private Set<Vacation> vacations = new HashSet<Vacation>();

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String name) {
		this.email = name;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	// public Set<Vacation> getVacations() {
	// return this.vacations;
	// }

	// public void setVacations(Set<Vacation> vacations) {
	// this.vacations = vacations;
	// }

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "customer_id")
	private Long customerId;

	public Long getCustomerId() {
		return this.customerId;
	}

	public void setCustomerId(Long id) {
		this.customerId = id;
	}

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this,
				ToStringStyle.SHORT_PREFIX_STYLE);
	}

	/**
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((email == null) ? 0 : email.hashCode());
		return result;
	}

	/**
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		Customer other = (Customer) obj;
		if (email == null) {
			if (other.email != null) {
				return false;
			}
		} else if (!email.equals(other.email)) {
			return false;
		}
		return true;
	}

}
